<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Admin\Contract;
use DB;


class OfflineController extends Controller
{

    public function index(Request $request){
        if($request->expectsJson()){
            $sql = "SELECT A.*,B.batchNum FROM a_testplan A LEFT JOIN a_contract B ON A.contract_id = B.id ";
            $data = DB::select($sql);
            $jsonData['data'] = $data;
            return response()->json($jsonData);
        }else{
            return view('admin.offline.index');
        }

    }
    //导出试验数据
    public function offlineExport(Request $request){
        $contract_id = $request->id; //批次 id
        $data_batch = DB::table('a_contract')->find($contract_id);
        $data_gaiyao = DB::table('a_contract_gaiyao')->where('contract_id',$contract_id)->get()->toArray();
        $data_sample = DB::table('a_sample_info')->where('contract_id',$contract_id)->get()->toArray();
        $data_item = DB::table('a_item_data')->where('contract_id',$contract_id)->get()->toArray();
        foreach($data_sample as $key=>&$val){
            $val->inputsql = DB::table('a_input_data')->where('sample_info_id',$val->id)->get()->toArray();
        }
        unset($val);

        dd($data_batch,$data_gaiyao,$data_sample,$data_item);
    }

    //离线上传功能
    public function offlineUpload(){

    }

    //导入excel表数据
    public function offlineImport(){

    }

}
